package com.gilgamesh.mall.member.utils;

/**
 * Created by Peiyao.Wang on 2021/2/2
 *生成随机字符串对象
 * @author Peiyao.Wang
 * @date 2021/2/2
 */


public final class RandomStringUtil {

    //所有的大写字母
    private final static String BIG_WORD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    //所有的小写字母
    private final static String SMALL_WORD = "abcdefghijklmnopqrstuvwxyz";
    //所有的数字
    private final static String ALL_NUMBER = "0947296012847243435";

    //前段时间的加密规则

    private final static String[] beforeTimeStr = {"u","y","q","a","h","v","w","l","z","x"};

    //后端段时间的加密规则
    private final static String[] afterTimeStr = {"y","r","a","f","t","c","q","p","n","z"};

    /**
     * 生成一个32位的随机字符串
     */
    public static String getRandom32Bit(){
        String word = BIG_WORD + ALL_NUMBER+ SMALL_WORD;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < 32; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            System.out.println("ntlgedu5/RandomString/getRandom32Bit Exception:" + e.getMessage());
            return null;
        }
    }

    /**
     * 生成一个8位的随机字符串
     */
    public static String getRandom8Bit(){
        String word = BIG_WORD + ALL_NUMBER+ SMALL_WORD;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < 8; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 生成一个6位的随机字符串
     */
    public static String getRandom6Bit(){
        String word = BIG_WORD + ALL_NUMBER+ SMALL_WORD;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < 6; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 生成一个10位的随机字符串
     */
    public static String getRandom10Bit(){
        String word = BIG_WORD + ALL_NUMBER+ SMALL_WORD;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < 10; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 生成一个3位的纯数字字符串
     */
    public static String getNumberRandom6Bit(){
        String word = ALL_NUMBER ;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < 6; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 生成一个指定位数的纯数字字符串
     */
    public static String getNumberRandomaAppointBit(int appointNum){
        String word = ALL_NUMBER ;
        StringBuffer sb = new StringBuffer();
        try {
            for (int i = 0; i < appointNum; i++) {
                int random = (int)(Math.random() * word.length());
                char chars = word.charAt(random);
                sb.append(chars);
            }
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }



}
